package com.threeonemeeting.activity;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.threeonemeeting.Const;
import com.threeonemeeting.DataCenter;
import com.threeonemeeting.R;
import com.threeonemeeting.tab.BaseTabActivity;
import com.threeonemeeting.util.MiscUtil;

public class MainMy31Activity extends BaseTabActivity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ac_my31);

		// 检查当前用户是否已经登录，如果没有则显示登录界面
		final DataCenter dataCenter = DataCenter.getInstance();

		ImageView headerView = (ImageView) findViewById(R.id.my_header_image);
		String strImageUrl = Const.URL.BASE_HEADERIMG_URL
				+ dataCenter.currentLoginUserInfo.nUserId;
		MiscUtil.setImageView(headerView, strImageUrl);

		TextView nameView = (TextView) findViewById(R.id.my_name);
		nameView.setText(dataCenter.currentLoginUserInfo.strNickName);

		String strScore = "积分：" + dataCenter.currentLoginUserInfo.nCoin;
		strScore += "  账户余额：" + dataCenter.currentLoginUserInfo.fCharge + "元";
		TextView scoreView = (TextView) findViewById(R.id.my_score);
		scoreView.setText(strScore);

		TextView lastLoginView = (TextView) findViewById(R.id.my_lastlogin);
		lastLoginView.setText(dataCenter.currentLoginUserInfo.strLastLoginTime);

		// 退出
		Button btnExit = (Button) findViewById(R.id.btn_exitlogin);
		if (btnExit != null) {
			btnExit.setOnClickListener(new OnClickListener() {

				public void onClick(View v) {

					dataCenter.currentLoginUserInfo.clear();
					dataCenter.mainLoginUser.clear();
					dataCenter.listAccounts.users.clear();

					MiscUtil.setPrefer(Const.Pref.PREFS_KEY_MAIN_USER_ID, "");
					MiscUtil.setPrefer(Const.Pref.PREFS_KEY_CURRENT_USER_ID, "");

					// 跳转到登录界面
					MainMy31Activity.this.startActivity("LoginActivity");
				}
			});
		}

	}

	public void OnMyPublishMettingClick(View arg0) {
		Bundle bundle = new Bundle();
		bundle.putString("Title", "我发布的会议");
		startActivity("MyPubMeetingActivity", bundle);
	}

	public void OnMyJoinMettingClick(View arg0) {
		Bundle bundle = new Bundle();
		bundle.putString("Title", "我参加的会议");
		startActivity("MyJoinedMeetingActivity", bundle);
	}

	public void OnMySubscribeMettingClick(View arg0) {
		Bundle bundle = new Bundle();
		bundle.putString("Title", "我订阅的会议");
		startActivity("MySubedMeetingActivity", bundle);
	}

	public void OnMyCollectionMettingClick(View arg0) {
		Bundle bundle = new Bundle();
		bundle.putString("Title", "我收藏的会议");
		startActivity("MyFavedMeetingActivity", bundle);
	}

	public void OnMeetingNearByClick(View arg0) {
		startActivity("NearByMeetingListActivity");
	}

	public void OnPossibleInterestMettingClick(View arg0) {
		Bundle bundle = new Bundle();
		bundle.putString("Title", "您感兴趣的会议");
		startActivity("MySubedMeetingActivity", bundle);
	}
}
